# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=exabgp
pkgver=4.0.2.r2189.g113675f
pkgrel=1
epoch=2
groups=('blackarch' 'blackarch-networking' 'blackarch-defensive')
pkgdesc='The BGP swiss army knife of networking.'
arch=('any')
url='https://github.com/Exa-Networks/exabgp'
license=('custom:unknown')
depends=('python' 'python-ipaddr' 'python-nose' 'python-psutil')
makedepends=('git' 'python-pip' 'python-build' 'python-wheel')
backup=('etc/exabgp.conf')
source=("git+https://github.com/Exa-Networks/$pkgname.git"
        "$pkgname.service")
sha512sums=('SKIP'
            '225726cf424d9c2a23a2c0e9d3c7ed8c5cf03993f9518efd8e45079822b2d8cbc4d6fd18b49794beee522530478b57e5e3b268b3abd92442680cdd695504360d')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

prepare() {
  cd $pkgname

  sed -i 's|">=3.8.1,<=3.13"|">=3.8.1"|g' pyproject.toml
}

build() {
  cd $pkgname

  python -m build --wheel --outdir="$startdir/dist"
}

package() {
  cd $pkgname

  pip install \
    --verbose \
    --disable-pip-version-check \
    --no-warn-script-location \
    --ignore-installed \
    --no-compile \
    --no-deps \
    --root="$pkgdir" \
    --prefix=/usr \
    --no-index \
    --find-links="file://$startdir/dist" \
    $pkgname

  install -Dm 644 "$srcdir/$pkgname.service" \
    "$pkgdir/usr/lib/systemd/system/$pkgname.service"
  install -Dm 644 /dev/null "$pkgdir/etc/$pkgname.conf"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" doc/*.rst
  install -Dm 644 "doc/man/$pkgname.1" "$pkgdir/usr/share/man/man1/$pkgname.1"
  install -Dm 644 "doc/man/$pkgname.conf.5" \
    "$pkgdir/usr/share/man/man5/$pkgname.conf.5"
  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname" *.md
  install -Dm 644 LICENCE.txt "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

